package com.studio701.carguard.controller;


import com.studio701.carguard.pojo.CarState;
import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.service.ICarStateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-04-09
 */
@RestController
@RequestMapping("/car-state")
public class CarStateController {
    @Autowired
    ICarStateService iCarStateService;

    @ApiOperation("添加车辆信息")
    @PostMapping("/")
    public boolean insertCarState(@RequestBody CarState carState){
        return iCarStateService.save(carState);
    }

    @ApiOperation("修改车辆信息")
    @PutMapping("/")
    RespBean updateCarState(@RequestBody CarState carState){
        if (iCarStateService.updateById(carState)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }

    @ApiOperation("获取车俩信息")
    @GetMapping("/")
    CarState getById(Integer id){
        return iCarStateService.getById(id);
    }

}
